<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
 <link rel="stylesheet" href="../static/css/back/font.css">
 <link rel="stylesheet" href="../static/css/back/role.css">
    <link rel="stylesheet" href="../static/css/back/xadmin.css">
    <script type="text/javascript" src="../static/js/jquery-2.1.1.min.js"></script>
    
    <script type="text/javascript" src="../static/js/back/xadmin.js"></script>
    <script type="text/javascript" src="../static/js/back/ajax.js"></script>
    <script type="text/javascript" src="../static/js/back/utils.js"></script>
    
<!--      <script type="text/javascript" src="../static/js/back/admin-rule.js"></script> -->
   
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
.layui-form-label {
	width: 100px !important;
}

td span {
	position: absolute;
	right: -8px;
	top: 18px;
}
</style>
  </head>
  
  <body>
   <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="javascript:;">首页</a>
        <a href="javascript:;">门店管理</a>
        <a href="javascript:;"><cite>配送设置</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="iconfont icon-refresh right-top-ref" ></i></a>
    </div>
    <div class="x-body">
      <form action="" method="post" class="layui-form" lay-verify="formAdd" onsubmit="javascript:return false;">
      <input type="hidden" name="id" value="" id="paramKey" />
      <div class="layui-form-item">
        <label for="name" class="layui-form-label"> <span
          class="x-red">*</span>配送范围
        </label>
        <div class="layui-input-inline">
          <input type="text" id="adTitle" name="shop_send_distance"  
             lay-verify="required"  autocomplete="off" class="layui-input"
            placeholder="配送范围">
        </div>
        <div class="layui-form-mid layui-word-aux">km</div>
      </div>
      <div class="layui-form-item">
        <label for="name" class="layui-form-label"> 配送方式 </label>
        <div class="layui-input-inline">
            <input type="text"  autocomplete="off" class="layui-input" value="商家配送" readonly="readonly"/>
            <div class="layui-inline layui-word-aux">目前仅支持商家配送</div>
<!--          <select class="pIdsel" name="pId"  lay-verify="" lay-search="" value="商家配送"> -->
<!--                <option value="">无</option> -->
<!--              </select> -->
        </div>
      </div>
      <div class="layui-form-item">
        <label for="name" class="layui-form-label"> 配送费用 </label>
        <div class="layui-input-block" >
          <table class="layui-table" style="width: 300px;">
                  <thead>
                    <tr>
                      <th>距离(km)</th>
                      <th>费用(元)</th>
                      </tr>
                  </thead>
                  <tbody>
                 <!--  <tr>
                    <td>
                    <div class="td-juli"> 
                    <div class="layui-input-inline " style="width: 50px;">
                      <input type="text" name="juli_min" placeholder=""   autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid">-</div>
                      <div class="layui-input-inline" style="width: 50px;">
                        <input type="text" name="juli_max" placeholder="" autocomplete="off" class="layui-input">
                      </div>
                    </div>
                    </td>
                    <td>
                      <div class="layui-input-inline" style="width: 50px;">
                        <input type="text" name="price_max" placeholder="￥" autocomplete="off" lay-verify="number"  class="layui-input">
                      </div>
                      <span><a title="删除" onclick="del_time(this)" href="javascript:;"> <i class="iconfont icon-delete x-red"></i></a></span>
                 </td>
                  </tr> -->
                  </tbody>
              </table>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="phone" class="layui-form-label"></label> 
        <div class="layui-input-inline">
          <button class="layui-btn"  onclick="addKmP()">添加配送费用</button>
        </div>
      </div>
      <div class="layui-form-item is_up_do hide">
        <label class="layui-form-label">外卖付款方式</label>
        <div class="layui-input-block">
          <input type="radio" name="payTypeOut" value="3" title="微信+线下" checked="" lay-filter='stat'> 
          <input type="radio" name="payTypeOut" value="1" title="微信支付" lay-filter='stat'>
          <input type="radio" name="payTypeOut" value="2" title="现金结算" lay-filter='stat'>
        </div>
      </div>
      <div class="layui-form-item ">
        <label class="layui-form-label"></label>
        <button class="layui-btn" lay-submit="" lay-filter="add">保存</button>
      </div>
    </form>
    </div>
    <script type="text/javascript">
    	
    
    
    </script>
    <script>
    _ddd = null;
          function del_time(obj){
            $(obj).parent().parent().parent().remove();
          }
          var spid = getCookie('shop_id');
          function  saveT(){
            var _map = {};
            var str = $('input[name="juli_min"]');
            var end = $('input[name="juli_max"]');
            var price = $('input[name="price_max"]');
            
            var kmp = "";
            for (var i = 0; i < str.length; i++) {
	            var start = str[i];
	            var endrt = end[i];
	            var pri = price[i];
	            kmp += $(start).val() + '-' + $(endrt).val() +'-' + ($(pri).val() * 100 ).toFixed(0);
	            if((i+1)!=str.length){
	            	kmp+=',';
	            }
            }
            _map['shopSendDistance']= $('input[name="shop_send_distance"]').val();
            _map['id']=  spid;
            _map['shopSendPrice']= kmp;
            _map['payTypeOut'] = $('input:radio[name="payTypeOut"]:checked').val();
            _ajax_post_token('../shop/updateShopInfoOnly.do',_map,function(res){
               layer.msg('保存成功!',{icon:6,time:2000});
            });
          }
          $(function(){
            _ajax_post_token('../shop/getShopById',{id:spid},function(res){
              console.log(res);
              if(res.returnObject){
            	$('input[name="shop_send_distance"]').val(res.returnObject.shopSendDistance);
                var tims = res.returnObject.shopSendPrice;
                var ts = tims.split(',');
                var html = '';
                console.log(res.returnObject.payTypeOut);
                $("input[name=payTypeOut][value="+res.returnObject.payTypeOut+"]").prop("checked", true);
                //form.render('radio');
                console.log(ts);
                for (var i = 0; i < ts.length; i++) {
                	if(ts[i]){
                	console.log(ts[i]);
                		 if(ts[i].split("-").length == 1 ){
                         	return;
                         }
                	}
                html ='  <tr> <td> <div class="td-juli">  <div class="layui-input-inline " style="width: 50px;">'
                    +' <input type="text" name="juli_min" value="'+ts[i].split("-")[0]+'" placeholder="" lay-verify="number" autocomplete="off" class="layui-input">'
                    +' </div> <div class="layui-form-mid">-</div> <div class="layui-input-inline" style="width: 50px;">'
                    +' <input type="text" name="juli_max" value="'+formatNullData(ts[i].split("-")[1])+'" lay-verify="number"  placeholder="" autocomplete="off" class="layui-input">'
                    +' </div> </div> </td> <td> <div class="layui-input-inline" style="width: 50px;">'
                    +' <input type="text" name="price_max" value="'+(ts[i]?(ts[i].split("-")[2]/100).toFixed(2):"")+'"  lay-verify="number" placeholder="￥" autocomplete="off" class="layui-input"> </div>'
                    +' <span><a title="删除" onclick="del_time(this)" href="javascript:;"> <i class="iconfont icon-delete x-red"></i></a></span>'
                    +' </td> </tr>';
                    $('.layui-table tbody').append(html);   
              	}  
              }
            });
          })
          function addKmP(){
            var html ='  <tr> <td> <div class="td-juli">  <div class="layui-input-inline " style="width: 50px;">'
               +' <input type="text" name="juli_min" placeholder="" lay-verify="number" autocomplete="off" class="layui-input">'
               +' </div> <div class="layui-form-mid">-</div> <div class="layui-input-inline" style="width: 50px;">'
               +' <input type="text" name="juli_max" lay-verify="number"  placeholder="" autocomplete="off" class="layui-input">'
               +' </div> </div> </td> <td> <div class="layui-input-inline" style="width: 50px;">'
               +' <input type="text" name="price_max"  lay-verify="number" placeholder="￥" autocomplete="off" class="layui-input"> </div>'
               +' <span><a title="删除" onclick="del_time(this)" href="javascript:;"> <i class="iconfont icon-delete x-red"></i></a></span>'
               +' </td> </tr>';
          	$('.layui-table tbody').append(html);   
          }
          layui.use(['form','layer'], function(){
              $ = layui.jquery,
           	form = layui.form
            ,layer = layui.layer;
            //监听提交
            form.on('submit(add)', function(data){
          	  
          	 
              console.log(data.field);
              //updateRule(data.field);
              saveT();
              return false;
            });
            console.log(_ddd);
            form.render();
            form.val("formAdd", _ddd);
            form.render('radio');

          });
    </script>

  </body>

</html>